package aden.SifWar.EvtLog;

import java.io.IOException;

import aden.Generic.Gen2DPoint;
import aden.Generic.Param.GenParamData;
import aden.Generic.Param.GenParamException;
import aden.Generic.Param.GenParamInt;
import aden.Generic.Param.GenParamIter;
import aden.Generic.Param.GenParamNode;
import aden.SifWar.SifWarUnit;


public class SifWarEvtLogChangeRadio extends SifWarEvtLog
{
	public SifWarEvtLogChangeRadio(SifWarEvtLogMgr inMgr,
			                Gen2DPoint      inUnit,
			                int      inRadio)
	{
		super(inMgr);
		mUnit = inUnit;
		mRadio   = inRadio;
	}
		
	public boolean Process()
	{
		SifWarUnit theUnit = mMgr.GetPlayerMgr().FindUnit(mUnit);
		theUnit.ChangeRadio(mRadio);
		return true;
	}

	public boolean Export(GenParamNode inNode)
	{
		if (!inNode.Add(new GenParamInt("UX",mUnit.GetX())) ||
			!inNode.Add(new GenParamInt("UY",mUnit.GetY())) ||
			!inNode.Add(new GenParamInt("M",mRadio)))
		{
			return false;
		}
		return true;
	}

	public boolean Import(GenParamIter inIter)
	{
		try
		{
		   mUnit.SetX(inIter.GetNextIntContent());
		   mUnit.SetY(inIter.GetNextIntContent());
		   mRadio = inIter.GetNextIntContent();
		}
		catch (GenParamException e) 
		{
			return false;
		}
		return true;
	}
	
	public String GetDesc()
	{
		return "ChangeRadio at ("+Integer.toString(mUnit.GetX())+","+Integer.toString(mUnit.GetX())+") to "+
	           Integer.toString(mRadio);
	}
	
	private Gen2DPoint mUnit;
	private int mRadio;

}
